package top.lishuoboy.boot04thymeleaf.controller;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.map.MapUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

/**
 * @author lishuoboy
 * @date 2022/1/29 15:12
 */
@Slf4j
@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {

    @GetMapping("")
    private String index() {
        return "/thymeleaf/00index";
    }

    @GetMapping("/01hello")
    private String hello(Model model) {
        log.info("model=={}", model);
        List list = ListUtil.list(false, 1, "aa");
        Map map = MapUtil.builder()
            .put("str2", "李四").put("list2", list).build();
        model.addAttribute("str1", "张三")
            .addAttribute("list1", list)
            .addAllAttributes(map);
        log.info("model=={}", model);
        return "/thymeleaf/01hello";
    }

    /**
     * thymeleaf当返回null或者void时，默认跳转url对应的页面，本例为http://localhost:8080/thymeleaf/02null
     */
    @GetMapping("/02null")
    private Map null02() {
        return null;
    }

}
